package com.qdlc.p2p.biz.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.service.PayService;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.common.model.jpa.QueryParam;
import com.qdlc.p2p.dal.common.model.jpa.SearchFilter.Operators;
import com.qdlc.p2p.dal.dao.PayDao;
import com.qdlc.p2p.dal.dto.Pay;

@Service("payService")
public class PayServiceimpl implements PayService {

    @Resource
    private PayDao payDao;

    @Override
    public List<Pay> list(int enable) {
        return payDao.findByProperty("enable", enable);
    }

    @Override
    public Pay findByNid(String nid) {
        return payDao.findObjByProperty("nid", nid);
    }

    @Override
    public Pay findById(long id) {
        return payDao.find(id);
    }

    @Override
    public Pay save(Pay pay) {
        return payDao.save(pay);
    }

    @Override
    public Pay update(Pay pay) {
        return payDao.update(pay);
    }

    @Override
    public void delete(Pay pay) {
        payDao.delete(pay.getId());
    }

    /**
     * 查询支付接口列表
     *
     * @param pageNumber
     * @param pageSize
     * @param model
     * @return
     */
    @Override
    public PageDataList<Pay> list(int pageNumber, int pageSize, Pay model) {
        QueryParam param = QueryParam.getInstance().addPage(pageNumber, pageSize);
        if (model != null) {
            if (!StringUtil.isBlank(model.getEnable()) && model.getEnable() != 0) {
                param.addParam("enable", Operators.EQ, model.getEnable());
            }
        }
        return payDao.findAllPageList(param);
    }
}
